package com.wdh.minio.event;

import com.wdh.minio.bean.Order;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Component
@Slf4j(topic = "OrderListener")
public class OrderListener  {

    @EventListener(OrderCreateEvent.class)
    @Async
    public void onApplicationEvent(OrderCreateEvent event) {
        log.info(event.getMessage());
        Order source = (Order)event.getSource();
        try {
            TimeUnit.SECONDS.sleep(5);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        log.info(source.getAddress());
    }
}
